﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AJAXServiceProxyGeneration;

namespace AJAXCodeGenerator.Generator
{
    public partial class ScriptSharpRefector : UserControl, IGeneratorControl
    {
        public ScriptSharpRefector()
        {
            InitializeComponent();
        }

        private const string PATH = "assemblyPath";
        private const string NAMESPACE = "ns";
        private const string POCO_NAMESPACE = "poco";
        private const string EXCLUDES = "exc";
        private const string FILTER = "pfilter";

        #region IGeneratorControl Members
       
        public IGenerator GetGenerator()
        {
            ScriptSharpReflectorGenerator serviceGenerator = new ScriptSharpReflectorGenerator(this.txtNamespace.Text, this.txtPocoNamespace.Text, this.txtAssemblyPath.Text,this.txtPackageName.Text, this.txtExcludeNames.Text);
            return serviceGenerator;
        }


        public GeneratorSettings GetSettings()
        {
            GeneratorSettings settings = new GeneratorSettings();
            settings.Settings = new GeneratorSetting[]
            {
                new GeneratorSetting(NAMESPACE, this.txtNamespace.Text),
                new GeneratorSetting(PATH, this.txtAssemblyPath.Text),
                new GeneratorSetting(POCO_NAMESPACE, this.txtPocoNamespace.Text),
                new GeneratorSetting(FILTER, this.txtPackageName.Text),
                new GeneratorSetting(EXCLUDES, this.txtExcludeNames.Text)
            };
            return settings;

        }

        public void LoadSettings(GeneratorSettings generatorSettings)
        {
            foreach (GeneratorSetting setting in generatorSettings.Settings)
            {
                if (setting.Name.Equals(PATH))
                {
                    this.txtAssemblyPath.Text = setting.Value;
                }
                else if (setting.Name.Equals(NAMESPACE))
                {
                    this.txtNamespace.Text = setting.Value;
                }
                else if (setting.Name.Equals(POCO_NAMESPACE))
                {
                    this.txtPocoNamespace.Text = setting.Value;
                }
                else if (setting.Name.Equals(EXCLUDES))
                {
                    this.txtExcludeNames.Text = setting.Value;
                }
                else if (setting.Name.Equals(FILTER))
                {
                    this.txtPackageName.Text = setting.Value;
                }
            }

        }

        #endregion
    }
}
